package com.czk.controller;

import com.czk.entity.PageResult;
import com.czk.entity.Result;
import com.czk.entity.StatusCode;
import com.czk.model.TbOrder;
import com.czk.service.OrderService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/10/21 14:34
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    @PostMapping("/add")
    public Result add(@RequestBody TbOrder order) {
        orderService.add(order);
        return new Result(true, StatusCode.OK, "提交成功");
    }

    @PostMapping("/search/{page}/{size}")
    public Result findPage(@RequestBody Map<String, String> searchMap, @PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        Page pageResult = orderService.search(searchMap, page, size);
        long total = pageResult.getTotal();
        List result = pageResult.getResult();
        PageResult pageResult1 = new PageResult(total, result);
        return new Result(true, StatusCode.OK, "查询成功", pageResult1);
    }
}
